/****************************************************
 * Description: Entity for 角色权限
 * Copyright:   Copyright (c) 2013
 * Company:     beiwaionline
 * @author      bfsu
 * @version     1.0
 * @see
	HISTORY
    *  2013-08-08 bfsu Create File
**************************************************/

package com.bfsuolframework.security.entity;


import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import com.bfsuolframework.core.entity.Entity;
import com.bfsuolframework.core.entity.EntitySupport;
import com.bfsuolframework.core.utils.StringUtils;

public class RolePrivilege extends EntitySupport implements Entity {

    private static final long serialVersionUID = 1L;

    public RolePrivilege(){}
    public RolePrivilege(Long id){
        this.id = id;
    }

    private Long id;
    private Role role;//所属角色
    private String privilegeTitle;//权限名称
    private String privilegeCode;//权限编码
    private String functionList;//功能编码列表

    /**
     * @return 主键
     */
    public Long getId() {
        return id;
    }
    /**
     * @param 主键
     */
    public void setId(Long id) {
        this.id = id;
    }
    
    /**
     * @return 所属角色
     */
    public Role getRole() {
        return role;
    }
    
    /**
     * @param 所属角色
     */
    public void setRole(Role role) {
        this.role = role;
    }
    
    /**
     * @return 权限名称
     */
    public String getPrivilegeTitle() {
        return privilegeTitle;
    }
    
    /**
     * @param 权限名称
     */
    public void setPrivilegeTitle(String privilegeTitle) {
        this.privilegeTitle = privilegeTitle;
    }
    
    /**
     * @return 权限编码
     */
    public String getPrivilegeCode() {
        return privilegeCode;
    }
    
    /**
     * @param 权限编码
     */
    public void setPrivilegeCode(String privilegeCode) {
        this.privilegeCode = privilegeCode;
    }
    
    /**
     * @return 功能编码列表
     */
    public String getFunctionList() {
        return functionList;
    }
    
    /**
     * @param 功能编码列表
     */
    public void setFunctionList(String functionList) {
        this.functionList = functionList;
    }
    
    /**
     * @return 功能编码列表集合
     */
    public List<String> getFunctions() {
    	if(!StringUtils.isBlank(this.functionList)){
    		return StringUtils.splitToList(this.functionList, "\\|");
    	}
        return new ArrayList<String>();
    }
    
    /**
     * @param 功能编码列表集合
     */
    public void setFunctions(List<String> functions) {
        this.functionList = StringUtils.join(functions, "|");
    }

    public int hashCode() {
        return new HashCodeBuilder().append("RolePrivilege").append(this.getId()).toHashCode();
    }

    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (getClass() != obj.getClass())
            return false;
        if (!(obj instanceof RolePrivilege))
            return false;
        final RolePrivilege that = (RolePrivilege)obj;
        return new EqualsBuilder().append(this.getId(), that.getId()).isEquals();
    }

    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.SIMPLE_STYLE).append("RolePrivilege").append("ID="+this.getId()).toString();
    }

}

